home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / postscript.753 < prev    next >
Text File  |  1992-02-06  |  2KB  |  40 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f2\fswiss Helvetica;}
  2. \paperw13040
  3. \paperh10800
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 memory leaks Display PostScript\
  8. \
  9. Q:  I have an application that make repeated calls to 
  10. \b PSscreenlist()
  11. \b0 .  If I run /NextDeveloper/Apps/ProcessMonitor, choose Display Postscript from the pop-up list, and watch the virtual memory usage, it continually increases.  After a couple of hours or so, my system is on its knees thrashing away.  How can I prevent this memory leakage?\
  12. \
  13. A:  Many of the C-callable PostScript functions, including the aforementioned 
  14. \b PSscreenlist()
  15. \b0 , require the use of compound objects within their wrap definition.  Compound objects in PostScript are objects that are represented on the stack as a pointer to virtual memory where the data is actually stored.  Arrays and dictionaries are both examples of compound objects.\
  16. \
  17. The appkit's wrap functions do pop compound objects off the stack before returning to the calling functions.  However, the memory used to store compound objects is not freed when it is popped off the stack.  Also, Display PostScript does not garbage-collect these stray memory locations (although it does other garbage collection).  These two facts coupled together yield the growing program problem.  The way to solve this problem is to strategically place 
  18. \b PSsave()
  19. \b0  and 
  20. \b PSrestore()
  21. \b0  commands in your code.  Using 
  22. \b PSsave()
  23. \b0  and 
  24. \b PSrestore()
  25. \b0  in this manner is actually cheaper than a garbage-collection facility.  This has the effect of returning the unused yet unfreed virtual memory back to the system.  Remember that 
  26. \b PSsave()
  27. \b0  and 
  28. \b PSrestore()
  29. \b0  take some time to execute, so you should place them such that they get executed frequently enough to circumvent the memory leakage, but not so frequently as to cause performance problems.\
  30.  
  31. \fc0 \
  32. QA753\
  33. \
  34. Valid for 1.0\
  35. Valid for 2.0
  36. \pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\fc0 Entry:    Mon Aug 26 16:08:21 1991 by NextAnswers Administrator [qap]
  37. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 \
  38. \
  39.  
  40.